package com.example.com.skills_utf8;

import com.utils.Utils1;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class IsRunningActivity extends Activity{

	IsRunningActivity activity = this;
	

	private EditText et_input;
	private Button btn_do,btn_start_app;
	private TextView tv_status;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_isrunning);
		
		
		et_input = (EditText)findViewById(R.id.et_input);
		btn_do = (Button)findViewById(R.id.btn_do);
		tv_status = (TextView)findViewById(R.id.tv_status);
		btn_start_app = (Button)findViewById(R.id.btn_start_app);
		
		
		
		
		btn_do.setOnClickListener( new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				final String PackageName = et_input.getText().toString();
				
				//	String packageName = this.getApplicationContext().getPackageName();
					boolean bOnForegound =Utils1.isAppOnForeground(activity.getBaseContext(), PackageName );
					boolean bOnBackgound =Utils1.isAppOnBackground(activity, PackageName );
					String str ="";
					str +="前台: " + bOnForegound +"\r\n";
					str +="后台: " + bOnBackgound;
					tv_status.setText(str);
					
					
					
			
					
			}
		});
		
		btn_start_app.setOnClickListener( new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				final String PackageName = et_input.getText().toString();
				
				 ActivityManager activityManager = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
				 activityManager.killBackgroundProcesses(PackageName);
				 //activityManager.restartPackage( PackageName );  // 已不再有效
					 
			}
		});

		
		
	}
	
}
